<?php
namespace app\admin\controller\set;
use \app\admin\controller\AuthSite;
class Tags extends AuthSite{
    
    
    public function index(){
        $TagsManage = new \logic\set\tags\TagsManage($this->getUser());
        $data = $TagsManage->getList(['siteid'=> $this->siteId]);
        $this->assign(get_defined_vars());
        return $this->fetch();
    }
    
    public function open(){        
        $TagsManage = new \logic\set\tags\TagsManage($this->getUser());
        $data = $TagsManage->getList(['siteid'=> $this->siteId]);
        $this->assign(get_defined_vars());
        return $this->fetch();
    }
    
    /**
     * 获取所有标签列表
     */
    public function getlist(){
        $TagsManage = new \logic\set\tags\TagsManage($this->getUser());
        $data = $TagsManage->getList(['siteid'=> $this->siteId,'status'=> 1]);
        return $this->success('获取成功','',$data);
    }
    
    /**
     * 添加
     */
    public function add(){
        if( request()->isPost()){
            $param = array(
                'tagname'   => input('tagname'),
                'siteid'    => $this->siteId
            );
            $TagsManage = new \logic\set\tags\TagsManage($this->getUser());
            $id = $TagsManage->add($param);
            return $this->success('添加成功','/set/tags/open');
        }
    }
    
    /**
     * 修改
     */
    public function editall(){
        if( request()->isPost()){
            $param = input('data');
            $TagsManage = new \logic\set\tags\TagsManage($this->getUser());
            $id = $TagsManage->editAll($param);
            return $this->success('添加成功','/set/tags/open');
        }
    }
    
    /**
     * 修改状态
     */
    public function editstatus(){
        try{
            $id = input('id');
            $TagsManage = new \logic\set\tags\TagsManage($this->getUser());
            $result = $TagsManage->editStatus($id);
            return $this->success('成功');
        }catch(\think\Exception $e){
            return $this->error('失败');
        }
    }
}